from flask import g

from create_app import create_app
from settings.config import Config
from flask_restful import reqparse

from utils.JwtTools import JwtTool

app = create_app(Config)


@app.before_request
def gz():
    req = reqparse.RequestParser()
    req.add_argument("token",location="headers")
    args = req.parse_args()
    if not args["token"]:
        uid = 0
    else:
        payload = JwtTool().vaild(args["token"])
        if not payload:
            uid = 0
        else:
            uid = payload["uid"]
    g.uid = uid

